#!/bin/bash

#配置IP地址和网关
IP=$(ip a s ens33 | grep inet | head -1 | awk '{print $2}'| awk -F/ '{print $1}')
read -p "请输入要设置的IP地址：" name

if [ "$IP"! = "$name" ]; then
    nmcli connection modify ens33 ipv4.addresses $name/24  ipv4.gateway 192.168.1.2 ipv4.dns 8.8.8.8 autoconnect yes  ipv4.method manual
fi

systemctl restart network   &> /dev/null

#临时挂载本地光盘下载基本插件
mkdir /etc/yum.repos.d/old     &> /dev/null
mv /etc/yum.repos.d/* /etc/yum.repos.d/old   &> /dev/null
echo "[zijian]
name=zijian
baseurl=file:///mnt/cdrom/
gpgcheck=0" > /etc/yum.repos.d/zijian.repo
mkdir /mnt/cdrom
if [ "$(cat /etc/fstab | grep sr0 | awk '{print $1}')" == "/dev/sr0" ];
then
    echo "已经挂载，无需操作！"
else
    echo "/dev/sr0        /mnt/cdrom    iso9660    defaults        0 0" >> /etc/fstab  &> /dev/null
    mount -a          &> /dev/null
    yum clean all &> /dev/null
    yum repolist all &> /dev/null
fi
df -Th | grep /dev/sr0   &> /dev/null
if [ $? -eq 0 ];then
#    echo "/dev/sr0光盘已经成功挂载！"
else
    echo "/dev/sr0光盘并没有成功挂载"
fi

#下载wget
yum install -y wget &> /dev/null
#A=$(which wget)
#if [ $? -eq 0 ]; then
#     echo "wget下载完成"
#else
#     echo "wget未下载"
#fi

#selinux的开启与关闭
#selinux=$(cat /etc/selinux/config | grep  "^SELINUX=" | awk -F= '{print $2}' ) &> /dev/null

#if [ "$selinux" != "disabled" ]; then
    sed -i '/SELINUX=enforcing/c \SELINUX=disabled' /etc/selinux/config  &> /dev/null
#fi 

mv /etc/yum.repos.d/old/* /etc/yum.repos.d/


#网络base源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null

yum clean all &> /dev/null
yum repolist all &> /dev/null

yum install -y net-tools                     &> /dev/null
yum install -y vim-enhanced                  &> /dev/null
yum install -y psmisc                        &> /dev/null
yum install -y lftp                          &> /dev/null
yum install -y rsync                         &> /dev/null
yum install -y ntpdate                       &> /dev/null
yum install -y tree                          &> /dev/null
yum install -y bash-completion               &> /dev/null
yum install -y unzip                         &> /dev/null

#防火墙放行端口55555
firewall-cmd --add-port=55555/tcp --permanent &> /dev/null
firewall-cmd --reload                        &> /dev/null



#ssh配置

sed -ri '/#Port/c \Port 55555' /etc/ssh/sshd_config                          &> /dev/null
sed -ri 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config                     &> /dev/null
#sed -ri '/#PermitRootLogin yes/c \PermitRootLogin no' /etc/ssh/sshd_config   &> /dev/null
sed -ri '/PasswordAuthentication yes/c \PasswordAuthentication no' /etc/ssh/sshd_config   &> /dev/null
sed -ri '/PasswordAuthentication no/c \PasswordAuthentication yes' /etc/ssh/sshd_config   &> /dev/null
systemctl restart sshd &> /dev/null

#时间同步，每隔半个小时计划任务

echo "*/30 * * * * ntpdate 182.92.12.11" >> /var/spool/cron/root  &> /dev/null                                
init 6

